Skip to content

Exclude tests/phpunit from DeepSource PHP analysis - #3269

Open
NathanaelJonesIreland wants to merge 1 commit into
masterfrom
ci/deepsource-exclude-phpunit
Open

Exclude tests/phpunit from DeepSource PHP analysis#3269
NathanaelJonesIreland wants to merge 1 commit into
masterfrom
ci/deepsource-exclude-phpunit

Conversation

@NathanaelJonesIreland

@NathanaelJonesIreland NathanaelJonesIreland commented Aug 21, 2026

Copy link
Copy Markdown

The problem

DeepSource: PHP goes red on any PR that adds or edits a PHPUnit test file, regardless of what the PR does. The analyzer cannot resolve PHPUnit\Framework\TestCase — it lives under the already-excluded vendor/** — so every assert*() call in a test file is reported as "Call to an undefined method".

Measured on #3242, which is red right now: 56 findings, 55 of them of exactly this shape.

File Findings
tests/phpunit/styles/test_FrmStyle.php 33
tests/phpunit/misc/test_FrmCreateFile.php 15
tests/phpunit/styles/test_FrmStylesController.php 5
tests/phpunit/database/test_FrmMigrate.php 2
classes/models/FrmStyle.php 1

Sample: Call to an undefined method test_FrmStyle::assertNotEmpty(), …::assertSame(), …::assertTrue(), …::assertCount(), and Call to an undefined static method FrmUnitTest::tearDown().

It is not limited to new test files. #3256 merely edits tests/phpunit/fields/test_FrmFieldValidate.php — a file that already carried assertions on master — and draws the same class of finding.

Why test_patterns doesn't already handle it

.deepsource.toml already lists these paths under test_patterns, so this looks like it should be solved. It isn't: test_patterns relaxes the style and security categories but still reports bug-risk issues, and "undefined method" is bug-risk. exclude_patterns is the only setting that stops them.

Why these are definitely artifacts, not defects

  • stubs.php declares WP_UnitTestCase extends WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase, and both phpstan.neon and psalm.xml load stubs.php explicitly. That is precisely why PHPStan and Psalm are green on the same files DeepSource calls broken. DeepSource has no equivalent stub-path setting.
  • The PHPUnit matrix passes on both PHP 7.4 and PHP 8. A suite cannot pass while calling undefined methods.

Why exclusion is the right fix rather than a workaround

Every other analyzer in this repo already treats these files this way:

  • phpstan.neonexcludePaths: */tests/*
  • phpcs.xml → a list of rule exclusions scoped to tests/phpunit/*

This change brings DeepSource in line with them. Since the analyzer cannot resolve the base class, its findings on this directory are 100% false positives, so nothing of value is being given up.

Scoped deliberately to tests/phpunit/** rather than **/tests/**, so the JavaScript analyzer keeps covering tests/cypress — it currently passes there and this shouldn't touch it. test_patterns and both [[analyzers]] blocks are unchanged; TOML validated.

What this does and does not fix

It removes the recurring red. It is not cosmetic: the noise has real cost — this failure class has been re-diagnosed on #3242 across roughly a dozen separate triage passes, and it has trained everyone to read DeepSource: PHP as "probably nothing," which is exactly how a genuine finding gets waved through. #3234 merged with 6 open DeepSource threads and #3235 with 9, both on test files.

The one remaining finding on #3242 is a real (if arguable) one in product code — Use of insecure md5() function found in classes/models/FrmStyle.php, where the hash is an opaque cache-busting key rather than a credential. That belongs to #3242 and is deliberately left out of this PR.

Requesting a look from @Crabcyborg since this is a repo-wide CI policy change rather than a fix to my own branch.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Updated code analysis settings to exclude PHPUnit test files from DeepSource scanning.
    • Prevented incorrect undefined-method warnings for PHPUnit assertions in test files.

The PHP analyzer cannot resolve PHPUnit\Framework\TestCase, because it lives
under the already-excluded vendor/**. Every assert*() call in a PHPUnit test
file is therefore reported as "Call to an undefined method", so any PR that
adds or edits a test file goes red on DeepSource: PHP regardless of its
contents.

Measured on PR #3242: 56 findings, 55 of them of this shape (33 in
test_FrmStyle.php, 15 in test_FrmCreateFile.php, 5 in
test_FrmStylesController.php, 2 in test_FrmMigrate.php). PR #3256 draws the
same class of finding on the one test file it edits, a file that already
carried assertions on master.

test_patterns already lists these paths and is not sufficient: it relaxes the
style and security categories but still reports bug-risk issues such as
undefined methods. exclude_patterns is the only setting that stops them.

PHPStan and Psalm are green on the same files because both load stubs.php
explicitly (which declares WP_UnitTestCase -> WP_UnitTestCase_Base ->
PHPUnit\Framework\TestCase); DeepSource has no equivalent stub-path setting.
The green PHPUnit matrix is the other evidence these are artifacts: a suite
cannot pass while calling undefined methods.

Mirrors how every other analyzer in this repo already treats these files -
phpstan.neon excludes */tests/*, phpcs.xml excludes a list of rules for
tests/phpunit/*.

Scoped to tests/phpunit/** rather than **/tests/**, so the JavaScript
analyzer keeps covering tests/cypress (it currently passes there).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3247d320-e222-436f-a18d-4d18112e8136

📥 Commits

Reviewing files that changed from the base of the PR and between faa3000 and 63a5a4a.

📒 Files selected for processing (1)
  • .deepsource.toml

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The DeepSource configuration now excludes tests/phpunit/**. A comment documents the unresolved PHPUnit\Framework\TestCase dependency and explains why test_patterns does not prevent the resulting bug-risk reports.

Changes

DeepSource analysis configuration

Layer / File(s) Summary
Exclude PHPUnit tests from DeepSource
.deepsource.toml
Adds tests/phpunit/** to exclude_patterns and documents the analyzer limitation and related exclusions in phpstan.neon and phpcs.xml.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Merge Risk: ⚪ Minimal · up to 63a5a

The scoped PHPUnit analysis exclusion is merge-ready after normal checks and review; the rationale in the configuration should be corrected or clarified, but no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: excluding tests/phpunit from DeepSource PHP analysis.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/deepsource-exclude-phpunit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Aug 21, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in faa3000...63a5a4a on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Aug 21, 2026 8:04p.m. Review ↗
JavaScript Aug 21, 2026 8:04p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

NathanaelJonesIreland pushed a commit that referenced this pull request Aug 21, 2026
DeepSource: PHP fails this PR on PHP-A1004 ("Use of insecure md5() function")
at the new update_css_version() call. It is a false positive: the value is a
12-character content-derived cache-busting token written to
frm_last_style_update, not a password. The check's suggested remedy,
password_hash(), is salted and non-deterministic, so it would defeat the entire
mechanism -- the whole point is that identical stylesheet bytes must reproduce
an identical version string.

Suppressed at the line rather than repo-wide, following the existing skipcq
convention in this codebase (classes/views/frm-entries/show.php,
classes/views/frm-fields/back-end/field-options.php, and the phpcs-sniffs
CommentSpacingSniff which explicitly whitelists skipcq: comments). Note that
classes/models/ already contains seven md5()-for-cache-key calls of exactly this
kind (FrmAddon, FrmAntiSpam, FrmApplicationApi, FrmFormApi, FrmFormTemplateApi,
FrmStyleApi, FrmUsage), none annotated -- DeepSource only reports on lines the
diff touches, which is why this one surfaced and those did not.

The remaining DeepSource findings on this PR are all in tests/phpunit/, which is
what #3269 addresses; this commit does not duplicate that change.

Verified: php -l clean; the custom Formidable.Commenting.CommentSpacing sniff
passes on the file; php-cs-fixer --dry-run --allow-risky=yes exits 0 against the
LF form CI analyses (the working tree is CRLF via autocrlf, which cs-fixer
reports on its own and is unrelated to this change).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@NathanaelJonesIreland

Copy link
Copy Markdown
Author

Babysit note — labels added, no code touched.

This PR had no labels and no reviews since it was opened 3h ago, which made its check status misleading rather than green. Every gate that would actually exercise the change read SKIPPED: PHPCS, PHP CS Fixer, PHP Syntax, Rector, ESLint, Oxlint, Stylelint, Cypress, and the whole PHP x WP test matrix. The only SUCCESS entries were the third-party analysers that run unconditionally (CodeRabbit, DeepSource, Scrutinizer, Psalm, Mago, DeepScan, typos). Core CI here is label-gated, so an unlabelled PR reports a clean rollup while having run essentially nothing.

Added run analysis + run tests so the real gates execute, and franky-review so a reviewer is actually queued — nothing was coming otherwise.

The two bot comments from this run are both clean and need no action: CodeRabbit reports "no actionable comments were generated", DeepSource reports grade A on faa3000...63a5a4a.

Left entirely alone otherwise: this is a core product repo, so no fix, push or merge from the automation — it needs a human approval, which a bot pass does not substitute for.

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config-only change, well-reasoned. .deepsource.toml gains one exclude entry (tests/phpunit/**) plus an inline comment explaining why: DeepSource's PHP analyzer can't resolve PHPUnit\Framework\TestCase (declared via vendor/**, which is already excluded), so every assert*() call in a test file reads as an undefined-method call — a bug-risk finding that test_patterns doesn't suppress (it only relaxes style/security).

Checked:

  • Mirrors existing precedent: phpstan.neon's excludePaths: */tests/* and phpcs.xml's tests/phpunit/* exclusions already treat this directory the same way.
  • Scoped to tests/phpunit/**, not **/tests/**tests/cypress (JS analyzer) is untouched, confirmed still passing in this PR's own checks.
  • DeepSource: PHP is green on this PR's head commit with the new config applied, and the PHP 7.4/8 test matrix passes — consistent with "these were false positives, not real failures."
  • No linked issue to route a reviewer request to.

Nothing blocking. Approving.

@NathanaelJonesIreland

Copy link
Copy Markdown
Author

Operator pass — merge-ordering note for whoever reviews this, since two other open PRs
are currently red on the check this PR configures.

DeepSource: PHP is failing on #3242 and #3256. I went through every DeepSource
review comment on both and split them by path:

PR findings in tests/phpunit/ findings in production code
#3242 8 (all in test_FrmStyle.php) 1 — md5() "insecure hash" on classes/models/FrmStyle.php:462
#3256 8 (all in test_FrmFieldValidate.php) 1 — Cannot access property $required on array|int|object, FrmFieldUrl.php:89

So merging this PR first strips the bulk of the noise off both, but does not on its own
turn either green — one production finding survives in each. Both look like false positives
worth a human's call rather than a code change:

Not proposing a change to this PR — just flagging that "merge #3269 and the others go green"
would be half right, so nobody is surprised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants